using System;
using System.Collections.Generic;
using System.Text;
using Xeml.Document;
using Xeml.Document.Contracts;
using Mpi.Common.Collections;

namespace Xeml.Sampling
{
    public class SampleColumnEmitter : ColumnEmitter
    {
        public override void Emit(IDocument xemlDoc)
        {
            this._columns.Clear();
            SampleColumn sc;
            
            

            sc = new SampleColumn();
            sc.DataType = typeof(string);
            sc.ExperimentName = xemlDoc.Name;
            sc.Name = "Experiment";
            sc.Enabled = true;
            sc.Target = SamplePropertyTarget.ExperimentName;
            this._columns.Add(sc.Name, sc);

            sc = new SampleColumn();
            sc.DataType = typeof(int);
            sc.Name = "SampleId";
            sc.Enabled = true;
            sc.Target = SamplePropertyTarget.Id;
            this._columns.Add(sc.Name, sc);

            sc = new SampleColumn();
            sc.DataType = typeof(int);
            sc.Name = "HashCode";
            sc.Enabled = true;
            sc.Target = SamplePropertyTarget.ReplicaGroup;
            this._columns.Add(sc.Name, sc);

            sc = new SampleColumn();
            sc.DataType = typeof(TimeSpan);
            sc.Name = "Time";
            sc.Enabled = true;
            sc.Target = SamplePropertyTarget.Time;
            this._columns.Add(sc.Name, sc);

            sc = new SampleColumn();
            sc.DataType = typeof(DateTime);
            sc.Name = "Real time";
            sc.Enabled = true;
            sc.Target = SamplePropertyTarget.RealTime;
            this._columns.Add(sc.Name, sc);

            sc = new SampleColumn();
            sc.DataType = typeof(string);
            sc.Name = "StoryLabel";
            sc.Enabled = true;
            sc.Target = SamplePropertyTarget.StoryLabel;
            this._columns.Add(sc.Name, sc);

            sc = new SampleColumn();
            sc.DataType = typeof(string);
            sc.Name = "GermPlasm";
            sc.Enabled = true;
            sc.Target = SamplePropertyTarget.GermPlasm;
            this._columns.Add(sc.Name, sc);

            sc = new SampleColumn();
            sc.DataType = typeof(string);
            sc.Name = "DevelopmentalStage";
            sc.Enabled = true;
            sc.Target = SamplePropertyTarget.DevelopmentalStage;
            this._columns.Add(sc.Name, sc);


            sc = new SampleColumn();
            sc.DataType = typeof(string);
            sc.Name = "Material";
            sc.Enabled = true;
            sc.Target = SamplePropertyTarget.Material;
            this._columns.Add(sc.Name, sc);

            sc = new SampleColumn();
            sc.DataType = typeof(int);
            sc.Name = "IndividualCount";
            sc.Enabled = true;
            sc.Target = SamplePropertyTarget.IndividualCount;
            this._columns.Add(sc.Name, sc);

            sc = new SampleColumn();
            sc.DataType = typeof(string);
            sc.Name = "Individuals";
            sc.Enabled = false;
            sc.Target = SamplePropertyTarget.Individuals;
            this._columns.Add(sc.Name, sc);

            sc = new SampleColumn();
            sc.IsContainerColumn = true;
            sc.DataType = typeof(string);
            sc.Name = "ObservationPoint Annotations";
            sc.Enabled = false;
            sc.Target = SamplePropertyTarget.Individuals;
            this._columns.Add(sc.Name, sc);

            foreach (TreeNode<StoryBase> node in xemlDoc.StoryBoard)
            {
                foreach (ObservationPoint op in node.Content.ObservationPoints)
                {
                    foreach (TaggedAnnotation ann in op.Annotations)
                    {
                        if (!sc.SubColumns.ContainsKey(ann.Tag))
                        {
                            ObPointAnnotationColumn ac = new ObPointAnnotationColumn();
                            ac.DataType = typeof(string);
                            //ac.Time = obc2.Time;
                            ac.Tag = ann.Tag;
                           
                            sc.SubColumns.Add(ac.Name, ac);
                        }
                    }
                }
            }



        }

        public SampleColumnEmitter()
        {
            base._columns = new Dictionary<string, Column>();
            base.name = "Sample"; 
        }
    }
}
